# coding=utf-8
import os
import time

MAX_PNG_AMOUNT = 20
while True:
    files = os.listdir(".")
    # print files
    png_files = filter(lambda f: f.endswith(".png"), files)
    # print png_files
    files_times = map(lambda f: int(os.stat(f).st_mtime*10), png_files)
    # print files_times
    now_time = int(round(time.time() * 10))  # 百毫秒级时间戳
    for cnt in range(len(png_files)):
        if files_times[cnt] < now_time - MAX_PNG_AMOUNT:
            os.remove(png_files[cnt])
    time.sleep(5)
